/*
 *  GLObject.h
 *  GLRender
 *
 *  Created by Patrick zulian on 5/23/10.
 *  Copyright 2010 University  of Lugano. All rights reserved.
 *
 */

#ifndef GL_OBJECT_H
#define GL_OBJECT_H

#include <QtOpenGL>
#include "WMaterial.h"
#include "Texture.h"

class GLObject  {
private:
	bool uniqueBinding;
	WMaterial * material;
	Texture * tex;
	
	GLuint dlName;
public:
	GLObject() : uniqueBinding(false), dlName(0) { material = NULL; tex = NULL; }
	
	
	~GLObject() {  clear(); }
	
	inline
	bool hasMaterial() const { return material != NULL; }
	
	inline 
	WMaterial * getMaterial() const { return material; }
	
	inline
	void setMaterial(WMaterial * material, bool uniqueBinding = false)
	{
		clear();
		this->uniqueBinding = uniqueBinding;
		this->material = material;	
	}
	
	inline 
	void clear()
	{
		//if(uniqueBinding && material != NULL) delete material;
	}
	
	inline 
	bool hasDL() const { return glIsList(dlName); }
		
	
	inline
	GLuint getDLName() const { return dlName; }
	
	inline
	void setDLname(GLuint dlName) { this->dlName = dlName; }
	
	inline 
	void callDL() const { glCallList(dlName); }
	
	inline
	bool hasTexture() const { return tex != NULL; }
	
	inline
	Texture * getTexture() const { return tex; }
	
	inline
	void setTexture(Texture * tex) { this->tex = tex; }
	
	inline
	void copy(GLObject * other) 
	{
		this->uniqueBinding = other->uniqueBinding = false;
		this->material = other->getMaterial();
		this->tex = other->tex;
		this->dlName = other->dlName;
		
	}
};


#endif
